Download
FAQ
History
HomeHomeNext API
Search
Feedback
Divider

Web Modules

Web components and static Web content files such as images are called Web resources. A Web module is the smallest deployable and usable unit of Web resources in a J2EE application. A J2EE Web module corresponds to a Web application as defined in the Java Servlet Specification.

Web modules are typically packaged and deployed as Web archive (WAR) files. The format of a WAR file is identical to that of a JAR file. However, the contents and use of WAR files differ from JAR files, so WAR file names use a .war extension.

In addition to Web components and Web resources, a Web module can contain other files including:

The top-level directory of a Web module is the document root of the application. The document root is where JSP pages, client-side classes and archives, and static Web resources are stored.

The document root contains a subdirectory called /WEB-INF, which contains the following files and directories:

You can also create application-specific subdirectories (that is, package directories) in either the document root or the /WEB-INF/classes/ directory.

The WAR structure just described is portable; you could import it into any container that conforms to the Java Servlet Specification. However, you cannot deploy it on the J2EE 1.4 Application Server until it contains a runtime deployment descriptor. The runtime deployment descriptor is an XML file that contains information such as the context root, the JNDI names of the application's resources, and some J2EE implementation-specific parameters. The J2EE application server Web application runtime DD is named sun-web.xml and is located in /WEB-INF/ along with the Web application DD.

Creating a Web Module

You package Web module into a WAR using the J2EE 1.4 Application Server deploytool utility. To build and package the hello1 application into a WAR named hello1.war:

  1. In a terminal window, go to <INSTALL>/j2eetutorial14/examples/web/hello1/.
  2. Run asant build. This target will spawn any necessary compilations and copy files to the <INSTALL>/j2eetutorial14/examples/web/hello1/build/ directory.
  3. Start deploytool.
  4. Create a Web application called hello1 by running the New Web Application Wizard. Select FileRight ArrowNewRight ArrowWeb Application WAR.
  5. New Web Application Wizard
    1. Select the Create New Stand-Alone WAR Module radio button.
    2. Click Browse and in the file chooser, navigate to <INSTALL>/j2eetutorial14/examples/web/hello1/.
    3. In the File Name field, enter hello1.
    4. Click Choose Module File.
    5. In the WAR Display Name field enter hello1.
    6. Click Edit to add the content files.
    7. In the Edit Contents dialog, navigate to <INSTALL>/j2eetutorial14/examples/web/hello1/build/. Select duke.waving.gif, GreetingServlet.class, and ResponseServlet.class and click Add. Click OK.
    8. Click Next.
    9. Select the Servlet radio button.
    10. Click Next.
    11. Select GreetingServlet from the Servlet Class combo box.
    12. Click Finish.
  6. Select FileRight ArrowNewRight ArrowWeb Application WAR.
    1. Click the Add to Existing WAR Module radio button and select hello1 from the combo box. Since the WAR contains all of the servlet classes, you do not have to add any more content.
    2. Click Next.
    3. Select the Servlet radio button.
    4. Click Next.
    5. Select ResponseServlet from the Servlet Class combo box.
    6. Click Finish.

A sample hello1.war is provided in <INSTALL>/j2eetutorial14/examples/web/provided-wars/. To open this WAR with deploytool:

  1. Select FileRight ArrowOpen.
  2. Navigate to the provided-wars directory.
  3. Select the WAR.
  4. Click Open Module.
Divider
Download
FAQ
History
HomeHomeNext API
Search
Feedback
Divider

All of the material in The J2EE 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.